'==============================================================================
' LANG		: VBScript 
' NAME		: FCS-SampleScript Uninstall Anti-Spyware Products.vbs 
' VERSION	: 1.0003 3/2/2007
' Description 	: Script to uninstall Anti-Spyware Products   
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
' Copyright (C) 2007. Microsoft Corporation.  All rights reserved.
'
' NOTES		: ALL SAMPLE SCRIPTS BEGIN WITH THE SAME SETUP ELEMENTS
'                 You can use this script standalone or incoporate the 
'                 subroutines in this script into a larger script.
'==============================================================================
Option Explicit
Dim bDEBUG : bDEBUG=False 'Set to TRUE to help with script debugging.
' Constants Declarations
  Const WAIT_ON_RETURN = True
  Const DO_NOT_WAIT_ON_RETURN = False
  Const HIDE_WINDOW = 0
  Const SHOW_WINDOW = 1
  Const ThisComputer = "."
  '==========================================================
' Main Routine
  On Error Resume Next
  If bDEBUG then On Error Goto 0
  
' Create system objects
  Dim WshShell      : Set WshShell = WScript.CreateObject("WScript.Shell")
  Dim objRegistry   : Set objRegistry = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
			                            ThisComputer & "\root\default:StdRegProv")
  Dim objWMIService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
                                                     ThisComputer & "\root\cimv2")

' Call the installation functions
  'Call FCS_InstallXPSP2Hotfix
  'Call UninstallMcAfeeAV
  Call UninstallAntiSpywareProducts
  
' Clean up objects and exit
  Set objWMIService = Nothing
  Set objRegistry = Nothing
  Set WshShell = Nothing
  
  wscript.quit
  
'=====================================================================================
' SubRoutine UninstallAntiSpywareProducts
'       This routine uninstalls some common anti-spyware products using the display
'       name parameters in the SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall registry key
'       
'  INPUTS: None
'  OUTPUT: Logs MSI uninstall events
' ASSUMES: The existence of the WshShell and objRegistry objects
'          Uninstall executable is in the directory the script was executed from or 
'          in the file search PATH
'
' READ THESE NOTES!
'   NOTES: This script fairly generic and can be used to uninstall any product
'          if you know the display name string. HOWEVER you may need to write some
'          custom uninstall strings depending on the product.  See the UninstallString
'          parameter under the registry key.

' CAUTION: This routine uses the InStr() function to locate the input display name in the 
'          registry display name. It does not do a direct match. Passing a poorly formed 
'          parameter to this routine could have some very bad unintended consequences.
'          For example, if you pass the word Microsoft to this routine it will attempt
'          to uninstall every Microsoft product on the system!
'          
'======================================================================================
Sub UninstallAntiSpywareProducts

   
   Const HKEY_LOCAL_MACHINE = &H80000002
   Const UninstallRegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
  
   Dim SubKeyArray, SubKey, DisplayName, UninstallString, StartPtr, ProductGUID
   objRegistry.EnumKey HKEY_LOCAL_MACHINE, UninstallRegKey, SubKeyArray
 
   For Each SubKey In SubKeyArray
 	'Get the Display Name for this product
 	objRegistry.GetStringValue HKEY_LOCAL_MACHINE, UninstallRegKey & "\" & SubKey, "DisplayName", DisplayName

	
  'If bDEBUG then wscript.echo "DEBUG: Product display name is " & DisplayName

  	' Microsoft AntiSpyware
  	If Instr(DisplayName, "Microsoft AntiSpyware") > 0 Then 
  If bDEBUG then wscript.echo "DEBUG: Unistalling Microsoft AntiSpyware"
		objRegistry.GetStringValue HKEY_LOCAL_MACHINE, UninstallRegKey & "\" & SubKey, "UninstallString", UninstallString
		StartPtr = Instr(1,UninstallString,"/I") + 2
		ProductGUID = mid(UninstallString, StartPtr, 38)
		WshShell.Run "msiexec /x " & ProductGUID & " /q Reboot=""ReallySuppress""",HIDE_WINDOW,WAIT_ON_RETURN
		WshShell.LogEvent 4, "Uninstalled " & DisplayName
	End if
	
	' Ad-Aware
	If Instr(DisplayName, "Ad-Aware") > 0 Then 
  If bDEBUG then wscript.echo "DEBUG: Uninstalling Ad-Aware"
		objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
			UninstallRegKey & "\" & SubKey, "UninstallString", UninstallString
		StartPtr = Instr(1,UninstallString," ")
		WshShell.Run trim(mid(UninstallString, 1, StartPtr)) & " /S " & trim(mid(UninstallString, StartPtr, 100)),HIDE_WINDOW,WAIT_ON_RETURN
		WshShell.LogEvent 4, "Uninstalled " & DisplayName
	End If
	
	' Spybot
	If InStr(DisplayName, "Spybot - Search & Destroy") > 0  Then 
  If bDEBUG then wscript.echo "DEBUG: Uninstalling Spybot"
		objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
			UninstallRegKey & "\" & SubKey, "UninstallString", UninstallString
		WshShell.Run UninstallString & " /NORESTART /SILENT",HIDE_WINDOW,WAIT_ON_RETURN
		WshShell.LogEvent 4, "Uninstalled " & DisplayName
	End If
	
	' Add other products here
	
  Next
End Sub